﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace WindowsGame1
{
    public class Mouvement
    {
        public enum Direction
        {
            NordEst = 0,
            NordOuest = 1,
            SudOuest = 2,
            SudEst = 3
        }

        public enum Bord
        {
            Nord, 
            Ouest, 
            Sud, 
            Est
        }

        public static Vector2 NewPosition(Vector2 pointDepart, int angleEnvoi, double vitesse)
        {
            Vector2 pt = new Vector2();
            Direction dir = (Direction)(angleEnvoi / 90);
            int angle = (angleEnvoi % 90);
            
            // x cos y sin
            double deplX = Math.Cos((double)angle) * vitesse;
            double deplY = Math.Sin((double)angle) * vitesse;

            switch (dir)
            {
                case Direction.NordOuest :
                    pt.X = pointDepart.X - Math.Abs((int)deplX);
                    pt.Y = pointDepart.Y - Math.Abs((int)deplY);
                    break;
                case Direction.NordEst :
                    pt.X = pointDepart.X + Math.Abs((int)deplX);
                    pt.Y = pointDepart.Y - Math.Abs((int)deplY);
                    break; 
                case Direction.SudEst : 
                    pt.X = pointDepart.X + Math.Abs((int)deplX);
                    pt.Y = pointDepart.Y + Math.Abs((int)deplY);
                    break;
                case Direction.SudOuest : 
                    pt.X = pointDepart.X - Math.Abs((int)deplX);
                    pt.Y = pointDepart.Y + Math.Abs((int)deplY);
                    break;
            }           

            return pt;
        }

        public static int AngleResultat(int angle, Bord bord)
        {
            Direction dir = (Direction)(angle / 90);
            switch (dir)
            {
                case Direction.NordOuest:
                    switch (bord)
	                {
                        case Bord.Nord:
                            return 360 - angle;
                            
                        case Bord.Ouest:
                            return 90 - (180 -(90 + (180 - angle)));
                            
                        case Bord.Sud:
                            return angle;
                            
                        case Bord.Est:
                            return angle;
                            
                        default:
                            return angle;
                            
	                }                   
                case Direction.NordEst:
                    switch (bord)
                    {
                        case Bord.Nord:
                            return 360 - (90 - angle);
                            
                        case Bord.Ouest:
                            return angle;
                            
                        case Bord.Sud:
                            return angle;
                            
                        case Bord.Est:
                            return 90 + 180 - angle ;
                            
                        default:
                            return angle;
                            
                    }

                case Direction.SudEst:
                    switch (bord)
                    {
                        case Bord.Nord:
                            return angle;
                            
                        case Bord.Ouest:
                            return angle;
                            
                        case Bord.Sud:
                            return 360 - angle;
                            
                        case Bord.Est:
                            return 180 + (360 - angle);
                            
                        default:
                            return angle;
                            
                    } 

                case Direction.SudOuest:
                    switch (bord)
                    {
                        case Bord.Nord:
                            return angle;
                            
                        case Bord.Ouest:
                            return 360 - (angle - 180);
                            
                        case Bord.Sud:
                            return angle - 180;
                           
                        case Bord.Est:
                            return angle;
                            
                        default:
                            return angle;
                            
                    }
                default:
                    return angle;

            }

        }



    }
}
